<?php

namespace App\Models\dispatch;

use App\Models\AdminModel;
use App\Models\AgentModel;
use App\Models\DictionaryModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class CarModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_dispatch_car';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    const TYPE = [1 => '港车', 2 => '内地车', 3 => '其他'];

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];


    //创建人
    public function create_admin(): BelongsTo {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }

    //代理商
    public function agent(): BelongsTo {
        return $this->belongsTo(AgentModel::class, 'agent_id');
    }

    //大陆司机
    public function driver(): BelongsTo {
        return $this->belongsTo(DriverModel::class, 'driver_id');
    }

    //香港司机
    public function hk_driver(): BelongsTo {
        return $this->belongsTo(DriverModel::class, 'hk_driver_id');
    }

    //车辆类型
    public function type(): BelongsTo {
        return $this->belongsTo(DictionaryModel::class, 'type_id');
    }

}
